﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using _01_Tower4._0.GameFrame.System;
using _01_Tower4._0.Interface;
using _01_Tower4._0;
using _01_Tower4._0.CharacterBase;
using static _01_Tower4._0.GameFrame.Game;
using static System.Net.Mime.MediaTypeNames;
using _01_Tower4._0.Scene;

namespace _01_Tower4._0.GameFrame.Manager
{
    internal class SceneManager : IGame
    {
        static public SceneManager? instance = null;
        public static SceneManager Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new SceneManager();
                }
                return instance;
            }
        }

        IScene[] scenes;
        ToolMenu toolMenu;
        CombatSystem cs;
        Map map;
        Hero hero;
        DialogSystem ds;
        SceneMenu sceneMenu;

        int currentSceneIndex;

        public static string sceneName;
        public static string lastSceneName;

        private SceneManager()
        {
            this.hero = hero;
        }
        public void Init()
        {
            scenes = new IScene[2];
            scenes[0] = new SceneMenu(sceneMenu);
            scenes[1] = new SceneMap1(cs, map, ds,hero);
            currentSceneIndex = 0;

            for (int i = 0; i < scenes.Length; i++)
            {
                scenes[i].Init();
            }
        }

        public void Input()
        {
            scenes[currentSceneIndex].Input();
        }

        public void Render()
        {
            scenes[currentSceneIndex].Render();
            //for (int i = 0; i < scenes.Length; i++)
            //{
            //    scenes[i].Render();
            //}
        }

        public void Update()
        {
            scenes[currentSceneIndex].Update();
            //for (int i = 0; i < scenes.Length; i++)
            //{
            //    scenes[i].Update();
            //}
        }

        public void FixUpdate()
        {
            for (int i = 0; i < scenes.Length; i++)
            {
                scenes[i].FixUpdate();
            }
        }

        public void End()
        {
            for (int i = 0; i < scenes.Length; i++)
            {
                scenes[i].End();
            }
        }

        public void ChangeSceneByName(string name)
        {
            for (int i = 0; i < scenes.Length; i++)
            {
                if (scenes[i].Name == name)
                {
                    currentSceneIndex = i;
                    Console.Clear();
                    return;
                }
            }
        }
    }
}
